package com.mall.web.util;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class MoneyUtil {

	public static String getPageShowMoney(Integer moeny) {

		if (moeny == null || moeny < 0) {
			return "";
		}
		BigDecimal show = (new BigDecimal(moeny.longValue())).divide(new BigDecimal(100));
		return show.doubleValue() + "";
	}

	public static String getPageShowMoney(Integer moeny, int number) {
		if (moeny == null || moeny < 0) {
			return "";
		}
		BigDecimal show = (new BigDecimal(moeny.intValue())).divide(new BigDecimal(number));
		return show.doubleValue() + "";
	}

	public static String getPageShowLongMoney(Long moeny) {

		if (moeny == null || moeny < 0) {
			return "";
		}
		BigDecimal show = (new BigDecimal(moeny.longValue())).divide(new BigDecimal(100));
		return show.doubleValue() + "";
	}

	public static String getPageShowLongMoney(Long moeny, int number) {
		if (moeny == null || moeny < 0) {
			return "";
		}
		BigDecimal show = (new BigDecimal(moeny.intValue())).divide(new BigDecimal(number));
		return show.doubleValue() + "";
	}
	
	public static Long getDBMoney(Long moeny){
		return (new BigDecimal(moeny)).multiply(new BigDecimal(100)).longValue();
	}

	public static void main(String[] args) {
		Long money = 0l;
		DecimalFormat df = new DecimalFormat("#,###0.00");
        System.out.println(df.format(0));
	}
	
	/**
	 * 用户金额按3位加逗号显示，保留小数点后两位
	 */
	public static String getDouhaoMoney(Long money){
		if(money == null || money < 0){
			return null;
		}
		DecimalFormat df = new DecimalFormat("#,###0.00");
        String douhaoMoney = df.format((new BigDecimal(money.intValue())).divide(new BigDecimal(100)).doubleValue());  
		return douhaoMoney;
	}
	
	/**
	 * eshop显示金额和实际买卖价格转换
	 * @param showPrice
	 * @return
	 */
	public static Integer getEshopPrice(String showPrice){
		if(showPrice == null || showPrice.equals("")){
			return 0;
		}
		return new BigDecimal(Double.parseDouble(showPrice.trim().replaceAll("万", ""))).multiply(new BigDecimal("10000")).intValue();
	}
	
	/**
	 * 将字符串中文转化成Long
	 * @param price
	 * @return
	 */
	public static Long getPriceByString(String price){
		if(price == null || price.equals("")){
			return 0l;
		}
		return new BigDecimal(Double.parseDouble(price)).multiply(new BigDecimal("100")).longValue();
	}
	
	//分销商设置时价格显示
	public static String getPriceByLongPrice(Long price){
		if(price == null || price < 0){
			return "0";
		}
		BigDecimal show = (new BigDecimal(price.longValue())).divide(new BigDecimal(100));
		return show+"";
	}
	
	//商品价格显示
	public static Double getItemPriceByLongPrice(Long price){
		if(price == null || price < 0){
			return null;
		}
		return new BigDecimal(price).divide(new BigDecimal(100)).doubleValue();
	}
	

}